import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('列表'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: ListView.custom(
        childrenDelegate: SliverChildBuilderDelegate((
          BuildContext context,
          int index,
        ) {
          return ListTile(
            leading: Icon(Icons.home),
            title: Text('早起的年轻人 $index'),
            subtitle: Text('今天 正在写代码中。。。'),
          );
        }),
      ),
    );
  }

  ListView buildListView2() {
    return ListView.separated(
      itemCount: 100,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          leading: Icon(Icons.home),
          title: Text('早起的年轻人 $index'),
          subtitle: Text('今天 正在写代码中。。。'),
        );
      },
      separatorBuilder: (BuildContext context, int index) {
        return Divider();
      },
    );
  }

  //
  ListView buildListView1() {
    return ListView.builder(
      itemCount: 100,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          leading: Icon(Icons.home),
          title: Text('早起的年轻人 $index'),
          subtitle: Text('今天 正在写代码中。。。'),
        );
      },
    );
  }

  //使用构造函数
  ListView buildListView() {
    return ListView(
      children: [
        ListTile(
          leading: Icon(Icons.home),
          title: Text('早起的年轻人'),
          subtitle: Text('今天 正在写代码中。。。'),
        ),
        ListTile(leading: Icon(Icons.home), title: Text('早起的年轻人')),
        ListTile(leading: Icon(Icons.home), title: Text('早起的年轻人')),
      ],
    );
  }
}
